/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entidades;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 *
 * @author Cott
 */
@Entity
@Table(name = "ARTICULO")
@NamedQueries({
    @NamedQuery(name = "Articulo.findAllNames", query = "SELECT a.descrip FROM Articulo a"),
    @NamedQuery(name = "Articulo.findAll", query = "SELECT a FROM Articulo a"),
    @NamedQuery(name = "Articulo.findByDescrip", query = "SELECT a FROM Articulo a WHERE a.descrip = :descrip"),
    @NamedQuery(name = "Articulo.findByPrecio", query = "SELECT a FROM Articulo a WHERE a.precio = :precio"),
    @NamedQuery(name = "Articulo.findByCosto", query = "SELECT a FROM Articulo a WHERE a.costo = :costo"),
    @NamedQuery(name = "Articulo.findByVto", query = "SELECT a FROM Articulo a WHERE a.vto = :vto"),
    @NamedQuery(name = "Articulo.findByPartida", query = "SELECT a FROM Articulo a WHERE a.partida = :partida"),
    @NamedQuery(name = "Articulo.findByMinstock", query = "SELECT a FROM Articulo a WHERE a.minstock = :minstock"),
    @NamedQuery(name = "Articulo.findByCodigo", query = "SELECT a FROM Articulo a WHERE a.codigo = :codigo")})
public class Articulo implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Column(name = "DESCRIP")
    private String descrip;
    @Column(name = "PRECIO")
    private Double precio;
    @Column(name = "COSTO")
    private Integer costo;
    @Column(name = "VTO")
    @Temporal(TemporalType.DATE)
    private Date vto;
    @Column(name = "PARTIDA")
    private Integer partida;
    @Column(name = "MINSTOCK")
    private Integer minstock;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "CODIGO")
    private Integer codigo;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "articulo")
    private Collection<Venta> ventaCollection;
    @JoinColumn(name = "CODIGO_CAT", referencedColumnName = "CODIGO")
    @ManyToOne
    private Categoria categoria;

    public Articulo() {
    }

    public Articulo(Integer codigo) {
        this.codigo = codigo;
    }

    public String getDescrip() {
        return descrip;
    }

    public void setDescrip(String descrip) {
        String oldDescrip = this.descrip;
        this.descrip = descrip;
        changeSupport.firePropertyChange("descrip", oldDescrip, descrip);
    }

    public Double getPrecio() {
        return precio;
    }

    public void setPrecio(Double precio) {
        Double oldPrecio = this.precio;
        this.precio = precio;
        changeSupport.firePropertyChange("precio", oldPrecio, precio);
    }

    public Integer getCosto() {
        return costo;
    }

    public void setCosto(Integer costo) {
        Integer oldCosto = this.costo;
        this.costo = costo;
        changeSupport.firePropertyChange("costo", oldCosto, costo);
    }

    public Date getVto() {
        return vto;
    }

    public void setVto(Date vto) {
        Date oldVto = this.vto;
        this.vto = vto;
        changeSupport.firePropertyChange("vto", oldVto, vto);
    }

    public Integer getPartida() {
        return partida;
    }

    public void setPartida(Integer partida) {
        Integer oldPartida = this.partida;
        this.partida = partida;
        changeSupport.firePropertyChange("partida", oldPartida, partida);
    }

    public Integer getMinstock() {
        return minstock;
    }

    public void setMinstock(Integer minstock) {
        Integer oldMinstock = this.minstock;
        this.minstock = minstock;
        changeSupport.firePropertyChange("minstock", oldMinstock, minstock);
    }

    public Integer getCodigo() {
        return codigo;
    }

    public void setCodigo(Integer codigo) {
        Integer oldCodigo = this.codigo;
        this.codigo = codigo;
        changeSupport.firePropertyChange("codigo", oldCodigo, codigo);
    }

    public Collection<Venta> getVentaCollection() {
        return ventaCollection;
    }

    public void setVentaCollection(Collection<Venta> ventaCollection) {
        this.ventaCollection = ventaCollection;
    }

    public Categoria getCodigoCat() {
        return categoria;
    }

    public void setCodigoCat(Categoria categoria) {
        Categoria oldCodigoCat = this.categoria;
        this.categoria = categoria;
        changeSupport.firePropertyChange("codigoCat", oldCodigoCat, categoria);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (codigo != null ? codigo.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Articulo)) {
            return false;
        }
        Articulo other = (Articulo) object;
        if ((this.codigo == null && other.codigo != null) || (this.codigo != null && !this.codigo.equals(other.codigo))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return descrip;
    }

    public boolean hasCode(){
        return ( this.getCodigo() != null);
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }

}
